package com.epam.cdp.ejb.message.driven;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.epam.cdp.ejb.stateless.jms.JMSResourcePropertyStore;

@MessageDriven(
		activationConfig = { @ActivationConfigProperty(
				propertyName = "destinationType", propertyValue = "javax.jms.Queue"
		) }, 
		mappedName = JMSResourcePropertyStore.QUEUE_NAME)
public class JMSQueueProcessorBean implements MessageListener {

	private final static Log log = LogFactory.getLog(JMSQueueProcessorBean.class);
	
    public JMSQueueProcessorBean() {
    }
	
    @Override
    public void onMessage(Message message) {
    	log.info("Retrived message " + message);
    	if (message instanceof TextMessage) {
    		TextMessage textMessage = (TextMessage) message;
    		try {
				log.info("Message type is TextMessage, text = " + textMessage.getText());
			} catch (JMSException e) {
				log.error("Failed to get text from message", e);
			}
    	}
    }

}
